import {
  Component, inject,
  input,
  signal
} from '@angular/core';
import {TasksService} from '../tasks.service';
import {FormsModule} from '@angular/forms';
import {
  Router,
  RouterLink
} from '@angular/router';

@Component({
  selector: 'app-new-task',
  imports: [
    FormsModule,
    RouterLink
  ],
  templateUrl: './new-task.html',
  styleUrl: './new-task.css'
})
export class NewTask {
  userId = input.required<string>();
  enteredTitle = signal('');
  enteredSummary = signal('');
  enteredDate = signal('');
  private tasksService = inject(TasksService);
  private router = inject(Router);


  onSubmit(){
    this.tasksService.addTask(
      {
        title:this.enteredTitle(),
        summary:this.enteredSummary(),
        date:this.enteredDate(),
      },
      this.userId()
    );

    this.router.navigate(['/users',this.userId(),'tasks'],{
      replaceUrl:true,
    });

  }
}
